package org.sgx.gwteditors.testgallery.manual.samples;

import org.sgx.gwteditors.client.impl1.EditorFramework1;
import org.sgx.gwteditors.client.impl1.basetypes.Color;
import org.sgx.gwteditors.client.impl1.basetypes.SelectionList;
import org.sgx.gwteditors.client.impl1.complex.PropertyHaverEditor2;
import org.sgx.gwteditors.client.impl1.edbean.EditableBean;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class GwtEditorsTestEntryPoint1 implements EntryPoint {

	@Override
	public void onModuleLoad() {
		RootPanel parent = RootPanel.get();
		
		// do not forget of initialize the gwteditors framework !
		new EditorFramework1().start(); 

		/* we must instantiate the editable beans using GWT.create() ! */
		ShapeBean bean = GWT.create(ShapeBean.class);
		
		bean.setStrokeDashArray(
			new SelectionList<String>(
					new String[] { "", ".", "-", "- ." }, new String[] { "" }));
		bean.setFillColor(new Color("ffffff"));
		bean.setStrokeColor(new Color("000000"));
		

		VerticalPanel vp = new VerticalPanel();
		parent.add(vp); 
		
		PropertyHaverEditor2<ShapeBean> ed = new PropertyHaverEditor2<ShapeBean>();
		vp.add(ed.getWidget());

		ed.load(bean);
	}
	
	// The bean we want to edit

	public static abstract class ShapeBean implements EditableBean {

		Color fillColor, strokeColor;
		SelectionList<String> strokeDashArray;
		Integer strokeWidth;
		Double opacity = 1.0;

		public Color getFillColor() {
			return fillColor;
		}
		public void setFillColor(Color fillColor) {
			this.fillColor = fillColor;
		}
		public Color getStrokeColor() {
			return strokeColor;
		}
		public void setStrokeColor(Color strokeColor) {
			this.strokeColor = strokeColor;
		}
		public SelectionList<String> getStrokeDashArray() {
			return strokeDashArray;
		}
		public void setStrokeDashArray(SelectionList<String> strokeDashArray) {
			this.strokeDashArray = strokeDashArray;
		}
		public void setStrokeDashArraySelection(String val) {
			this.strokeDashArray.getSelection().clear();
			this.strokeDashArray.getSelection().add(val);
		}
		public Integer getStrokeWidth() {
			return strokeWidth;
		}
		public void setStrokeWidth(Integer strokeWidth) {
			this.strokeWidth = strokeWidth;
		}
		public Double getOpacity() {
			return opacity;
		}
		public void setOpacity(Double opacity) {
			this.opacity = opacity;
		}
	}

}
